- item ||= f.object
- source_product = Maybe(item.source_product)
- variant = source_product.variant

%tbody.nested-fields.delivery-item.outgoing-parcel-item
  %tr
    %td.act
      - if f.object.destroyable?
        = link_to_remove_association(content_tag(:i) + h(:destroy.tl), f, 'data-no-turbolink' => true, class: 'destroy remove remove-item')
    %td.annotable.annotable--shipments
      = f.input :sale_item_id, as: :hidden
      - scopes = { deliverables: true, alive: true }
      - if item.source_product.blank?
        - variant_id = variant.id.or_else(nil)
        - scopes[:of_variant] = variant_id if variant_id
      = f.referenced_association(:source_product, wrapper: :nested, source: {controller: 'backend/matters', scope: scopes}, input_html: { data: {product_of_delivery_item: {url: backend_product_path("RECORD_ID", format: :json)}}}, hint: content_tag(:span, variant.name.or_else(nil), class: 'item-variant-name'))
      - if f.object.annotation.blank?
        = link_to("#", data: { annotate: ".annotate", use_closest: "tbody" }, title: :add_annotation.tl, class: "shipment-annotation") do
          %i
    %td
      .item-quantifier
        .item-quantifier-population
          :ruby
            hint = :x_unit.tl(quantity: "[QTY]", unit: "[UNT]")
              .gsub("[QTY]", content_tag(:span, source_product.population.or_else('&ndash;'.html_safe), class: "item-population-total"))
              .gsub("[UNT]", content_tag(:span, h(variant.unit_name.or_else('#')), class: "item-population-unit-name").html_safe)
          = f.input :population, wrapper: :nested_append, hint: hint.html_safe do
            = f.input_field :population, class: "item-population", placeholder: source_product.population.or_else(nil).to_s
            %span.add-on.item-population-unit-name= variant.unit_name.or_else('#')
      -# .errors= item.errors.inspect
    %td= f.referenced_association(:analysis, wrapper: :nested)

  %tr.tr-add-on
    %td{ colspan: 3 }
      - attrs = {}
      - attrs[:style] = "display: none" if f.object.annotation.blank?
      .annotate{attrs}= f.input(:annotation, wrapper: :nested, input_html: { class: "annotation" })
